<template>
  <div class="my-padding">

    <div class="my-padding">
      <el-table
        element-loading-text="Loading"
        :data="list"
        border
        fit
        style="width: 100%"
        highlight-current-row>
        <el-table-column label="模板名(以第一次文件名命名)" align="center">
          <template slot-scope="scope">{{ scope.row.substring(scope.row.lastIndexOf("/")+1) }}</template>

        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="handleUpload(scope.row)">下载</el-button>
          </template>
        </el-table-column>
      </el-table>

    </div>
  </div>
</template>
<script>
  import $ from "@/api/backUp"

  export default {
    name: 'BackUp',
    data() {
      return {
        activeName: "1",
        uploadId: '',
        isTrans: "",
        paths: "",
        claimsNumber: 'ZQ202009050010',
        types: '',
        name: '',
        createTime: '',
        createId: '',
        trueName: '',
        list: [],
        listLoading: true,
        value: '',
        uploadfile: "",
        updatefile: "",
      };
    },
    created() {

      this.fetchData();

      if (this.$route.query.activeName == null) {
        this.activeName = "first";
      } else {
        this.activeName = this.$route.query.activeName;
      }
    },
    methods: {
      fetchData() {
        $.findAllBackUp().then(response => {
          this.list = response.data;
          // console.log(response.data)
        });
      },
      handleUpload(id) {
        $.backUpDownload({uploadId: id}).then(response => {
          let blob = new Blob([response.data], {
            type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=gbk"
          });
          let fileName = decodeURI(
            response.headers["content-disposition"].split("=")[1]
          );
          if (window.navigator.msSaveOrOpenBlob) {
            navigator.msSaveBlob(blob, fileName);
          } else {
            var link = document.createElement("a");
            link.href = window.URL.createObjectURL(blob);
            link.download = fileName;
            link.click();
            //释放内存
            window.URL.revokeObjectURL(link.href);
          }
        })
      },

    }
  }
</script>
